home *** CD-ROM | disk | FTP | other *** search
- /*
- About TXTMENU
-
- This program is to generate a txt-menu in DOS. It is mainly for users to
- develop their own txt-based menu. It reads the .cfg file to get the menu
- contents and return diffrerent value to indicate the select result.
- It has wonderful sound effect and some time counting facility. Besides,
- it includes all SOURCE CODE !
-
- To start it just type the exe file and the program will work.
-
- With SOURCE CODE , you can easily modify it for your own purpose.
- You can distribute the source code freely only together with this readme
- file. Since this is a shareware, you are required to register in order
- to use it in your own program. It will only cost you $50.
-
- However, if you do not like to pay so much, you can also pay as much as you
- wish to register. Just think the time and energe you will save by this
- program !
-
- After you register for this program, you will get permission to
- include the source code to your own program. Besides,you will also
- get more detailed comments of the source code and you can get answers
- from author about any programming problems without extra fee.
-
- Money and Check should mail to:
-
- Mr. Yongyong Xu,
- 1940 Howard Street. Apt. 333,
- Kalamazoo, MI 49008
- U.S.A.
-
- Telephone: (616) 387-7569
- EMail: yxu@cs.wmich.edu (prefered)
- or
- 99xu1@grog.lab.cc.wmich.edu
-
- When you cannot reach me by the above address, try the next:
- -----------------------------------------------------------------------
- <Permanet Home Address>
-
- Mr. Xu Yongyong,
- Building 34 Room 604,
- HuayuanXinCun , Chang Zhou
- Jiang Su Province 213016
- P.R.China
-
- Tel:(86)-(519)-(328-0177)
-
-
- */
- #include <stdlib.h>
- #include <dos.h>
- #include <conio.h>
- #include <string.h>
- #include <stdio.h>
-
- #include "txtfunc.h"
-
- void back(int x1,int y1,int x2,int y2,int mode);
- void cursor_off();
- void cursor_on();
- void display_on();
- void display_off();
- char *char_malloc(short length);
-
- void back(int x1,int y1,int x2,int y2,int mode)
- {
- int i,j;
- int chare;
- if (mode==0) chare=176;
- else chare=178;
- for(i=x1;i<=x2;i++) {
- for(j=y1;j<=y2;j++) {
- gotoxy(i,j);
- cprintf("%c",chare);
- }
- }
- }
-
- void rect(int x1,int y1,int x2,int y2,int mode)
- {
- int i;
- int r1,r2,r3,r4,r5,r6;
- if (mode==0) {
- r1=218;r2=191;r3=192;r4=217;r5=179;r6=196;
- }
- else {
- r1=201;r2=187;r3=200;r4=188;r5=186;r6=205;
- }
- if (x1!=x2 && y1!=y2) {
- gotoxy(x1,y1);cprintf("%c",r1);
- gotoxy(x1,y2);cprintf("%c",r3);
- gotoxy(x2,y1);cprintf("%c",r2);
- gotoxy(x2,y2);cprintf("%c",r4);
- }
- else if (x1==x2) {
- gotoxy(x1,y1);cprintf("%c",r5);
- gotoxy(x1,y2);cprintf("%c",r5);
- }
- else if (y1==y2) {
- gotoxy(x1,y1);cprintf("%c",r6);
- gotoxy(x2,y1);cprintf("%c",r6);
- }
- for (i=x1+1;i<=x2-1;i++) {
- gotoxy(i,y1);
- cprintf("%c",r6);
- gotoxy(i,y2);
- cprintf("%c",r6);
- }
- for(i=y1+1;i<=y2-1;i++) {
- gotoxy(x1,i);
- cprintf("%c",r5);
- gotoxy(x2,i);
- cprintf("%c",r5);
- }
- }
-
- void face()
- {
- char s[80];
- display_off();
- textmode(C80);
- textcolor(WHITE);
- //textbackground(CYAN);
- textbackground(color1);
- window(1,1,80,25);
- clrscr();
- back(1,1,80,21,0);
- textcolor(YELLOW);
- back(1,22,80,22,1);
- textcolor(WHITE);
- rect(2,23,79,25,1);
- gotoxy(5,24);
- textcolor(LIGHTRED);
- cprintf("Enter");
- textcolor(WHITE);
- cprintf("=Continue ");
- textcolor(LIGHTRED);
- cprintf("Esc");
- textcolor(WHITE);
- cprintf("=Cancel");
- window(10,3,70,6);
- //textbackground(LIGHTBLUE);
- textbackground(color2);
- clrscr();
- window(1,1,80,25);
- rect(10,3,70,6,0);
-
- gotoxy(11+ (70-10-strlen(title0))/2 ,4);
- cprintf("%s",title0);
- gotoxy(11+ (70-10-strlen(title1))/2 ,5);
- cprintf("%s",title1);
- display_on();
- free(s);
- }
-
- void cursor_off()
- {
- union REGS r;
- r.h.ah=0x1;
- r.h.ch=0x20;
- r.h.cl=0x8;
- int86(0x10,&r,&r);
- }
-
- void cursor_on()
- {
- union REGS r;
- r.h.ah=0x1;
- r.h.ch=0x6;
- r.h.cl=0x7;
- int86(0x10,&r,&r);
- }
-
- void display_off()
- {
- union REGS r;
- r.h.ah=0x12;
- r.h.al=0x01;
- r.h.bl=0x36;
- int86(0x10,&r,&r);
- }
-
- void display_on()
- {
- union REGS r;
- r.h.ah=0x12;
- r.h.al=0x00;
- r.h.bl=0x36;
- int86(0x10,&r,&r);
- }
- /***************************************************************************
- * Module name : inputstring( x, y, instr,) *
- * Argument : x int, horizonal position. *
- * y int, vertical position. *
- * instr pointer to default and input *
- * string. *
- * Function : Input a string at the position *
- ***************************************************************************/
- void inputstring(int x,int y,char * instr)
- {
- char ch[2];
- int xcount, notok, term, i, first,xpos;
- /*xpos:where is cursor now */
- char *char_tmp;
- char_tmp=char_malloc(20);
- strcpy(char_tmp,instr);
- first=1; /*flag for input_char first? */
- term=0; /*ok? */
- xcount=strlen(instr); /*length of instr */
- textcolor(BLACK);
- textbackground(WHITE);
- gotoxy(x,y); /* print default string */
- cputs(instr);
- cursor_on();
- notok = 1; /*1:char invalid */
- /*0:char valid */
- do{
- ch[0] = getch();
- ch[1] = '\0';
- if( strlen( ch ) == 1) {
- if( ch[0] == ESC ) { /*ESC means no chang and quit */
- zxexit();
- /*
- notok = 0;
- strcpy(instr,char_tmp);
- term=1;
- first = 0;*/
- }
- else if( ch[0] == ENTER ) { /*ENTER means permit the chang */
- notok = 0;
- term=1;
- first = 0;
- }
- else if(ch[0]=='\t'){
- notok=1;
- term=0;
- first=1;
- }
- else if( ch[0] == BACKSPACE ) {
- xpos=wherex();
- if(xcount >= 1) {
- instr[xpos-x-1] = '\0';
- gotoxy( x, y );
- for( i = 0; i < xcount; i ++ ) /* delete the old string */
- putch(' ');
- gotoxy( x, y );
- cputs( instr ); /* write a new string */
- xcount --;
- notok = 0;
- }
- else {
- notok=1;
- }
- first = 0;
- term = 0;
- }
- else {
- if( first ) {
- first =0;
- xcount = 0;
- gotoxy(x, y);
- for(i=0;i<strlen(instr);i++) /* delete the old string */
- putch(' ');
- instr[0] = '\0'; /* clear the string */
- strcat( instr, ch );
- gotoxy( x + xcount, y );
- cputs( ch );
- xcount ++;
- notok = 0;
- term=0;
- }
- else{
- xpos=wherex();
- xcount ++;
- if(xcount <= 20 ) {
- strcat( instr, ch );
- gotoxy( xpos , y );
- cputs( ch );
- notok = 0;
- }
- else {
- xcount --;
- notok = 1;
- }
- term=0;
- }
- }
- }
- else {
- ch[1]=getch();
- notok=1;
- term=0;
- }
- if( notok ) putchar(7);
- }while( term == 0 );
- cursor_off();
- free(char_tmp);
- }
- /*┌─────────────────────────────────────────────────────────────────────────┐
- │ module name: datainput() │
- │ return: no │
- │ argument: *s │
- │ function: input datas in special window,and return datas in s. │
- └─────────────────────────────────────────────────────────────────────────┘*/
- void datainput(int x,int y,char *s,char *s1)
- {
- int length;
- length=strlen(s1);
- window(x,y,x+21+length,y+2);
- textcolor(WHITE);
- textbackground(LIGHTBLUE);
- clrscr();
- window(1,1,80,25);
- rect(x,y,x+21+length,y+2,0);
- window(x,y,x+21+length,y+2);
- gotoxy(2,2);
- textcolor(LIGHTCYAN);
- cprintf("%s",s1);
- textcolor(WHITE);
-
- inputstring(2+length,2,s);
- window(1,1,80,25);
- textbackground(BLUE);
- textcolor(WHITE);
- while (*s==' ') strcpy(s, s+1);
- }
- /*┌─────────────────────────────────────────────────────────────────────────┐
- │ module name: char_malloc() │
- │ return: *string │
- │ argument: length │
- │ function: malloc a string which length is length. │
- └─────────────────────────────────────────────────────────────────────────┘*/
- char *char_malloc(short length)
- {
- char *tmp;
- if((tmp=(char*)malloc(length))==NULL) {
- putch(7);
- cprintf("no free space!");
- zxexit();
- }
- return(tmp);
- }
-
-